package com.cqan.account.dao;


import java.util.List;

import org.hibernate.Query;
import org.hibernate.criterion.Projections;
import org.springframework.stereotype.Repository;

import com.cqan.account.entity.Resource;
import com.cqan.dao.HibernateDao;
import com.cqan.orm.Page;

@Repository("resourceDao")
public class ResourceDao extends HibernateDao<Resource,Long>  {

	/**
	 * @param page
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public Page<Resource> getAllMenu(Page<Resource> page) {
		String hql = "FROM Resource";
		Query query  = getSession().createQuery(hql);
		query.setFirstResult(page.getFirst()-1);
		query.setMaxResults(page.getPageSize());
		page.setResult(query.list());
		Integer totalCountObject = (Integer)getSession().createCriteria(Resource.class).setProjection(Projections.rowCount()).uniqueResult();
		page.setTotalCount(totalCountObject);
		return page;
	}

	

}
